
%% This file is part of the source-code demonstrating the method published 
% in the paper: 
%
% Wei Liu and Eraldo Ribeiro. Scale and Rotation Invariant Detection 
%      of Singular Patterns in Vector Flow Fields. IAPR International 
%      Workshop on Structural Syntactic Pattern Recognition (S-SSPR), 
%      Cesne, Turkey, 2010.
%
% BIBTEX ENTRY:
%
% @inproceedings{WeiRibeiroSSPR2010,
%   author    = {Wei Liu and Eraldo Ribeiro},
%   title     = {Scale and Rotation Invariant Detection of Singular 
%                Patterns in Vector Flow Fields},
%   booktitle = {IAPR International Workshop on Structural Syntactic 
%                Pattern Recognition (S-SSPR)},
%   year      = {2010},
%   pages     = {XXX-XXX}
% }
%
% The source-code can be obtained from 
%        http://www.cs.fit.edu/~eribeiro/flowdetector/
% 
% You are free to use, change, or redistribute this code in any way you
% want for non-commercial purposes. However, it is appreciated if you 
% maintain the name of the original authors.
%
% (c) 2010 by Wei Liu and Eraldo Ribeiro 
% eribeiro@cs.fit.edu
% Florida Instititute of Technology, Melbourne, Florida, U.S.A.
%

%%
tuv=read_ground_truth_old('run010050180.uvo');
norder=4;
lorder=4;
[toframes, todescr, gss,ess]=flow_singular_pattern_detect(tuv,'norder',norder,'lorder',lorder);

%% get screensize for displaying figures
scrsz = get(0,'ScreenSize');

%% display input flow data
figure( 'Color', 'w', ...
        'Position',[1 scrsz(4)/2 scrsz(3)/3 scrsz(4)/2]); 
spaced_quiver(tuv, 8, 'b');
title('Input flow field data', ...
'FontSize', 14);


%% display singular energy maps (sample maps)
figure( 'Color', 'w','MenuBar','none');     

subplot(4,3,1), imagesc(ess.octave{1}(:,:,1));
subplot(4,3,2), imagesc(ess.octave{1}(:,:,2));
subplot(4,3,3), imagesc(ess.octave{1}(:,:,3));

subplot(4,3,4), imagesc(ess.octave{2}(:,:,1));
subplot(4,3,5), imagesc(ess.octave{2}(:,:,2));
subplot(4,3,6), imagesc(ess.octave{2}(:,:,3));

subplot(4,3,7), imagesc(ess.octave{5}(:,:,1));
subplot(4,3,8), imagesc(ess.octave{5}(:,:,3));
subplot(4,3,9), imagesc(ess.octave{5}(:,:,6));

subplot(4,3,10), imagesc(ess.octave{6}(:,:,1));
subplot(4,3,11), imagesc(ess.octave{6}(:,:,3));
subplot(4,3,12), imagesc(ess.octave{6}(:,:,6));


%% display the frames
[height width nc]=size(tuv);
src=uint8(ones(height,width,3)*255);
figure('Color','w', ...
        'Position',[200 scrsz(4)/2 scrsz(3)/3 scrsz(4)/2]);
display_flow_features(tuv,8,toframes,'log');

%% calculate principle orientations
tpo=cell(size(todescr,2),1);
for ii=1:size(todescr,2)
    %tpo{ii}=principal_orientations(todescr(:,ii),0.7);
    %tpo{ii}=principal_orientations_coef_sum(todescr(:,ii),0.7); 
    tpo{ii}=principal_orientations_ext(todescr(:,ii),0.1, 0.7,norder,lorder);
end
%%
figure('Color','w', ...
        'Position',[300 scrsz(4)/2 scrsz(3)/3 scrsz(4)/2]);
display_flow_features_orientation(tuv,8,toframes,tpo,'log');
title('singular patterns with principle orientations', ...
'FontSize', 14);


%%
figure('Color','w', ...
        'Position',[400 scrsz(4)/2 scrsz(3)/3 scrsz(4)/2]);
tframes=toframes(:,toframes(4,:)>0.4);
display_flow_features(tuv,8,tframes,'log');
title('Displaying just the strongest singular patterns', ...
'FontSize', 14);

